package com.cyl.wms.controller;

import com.cyl.wms.domain.Material;
import com.cyl.wms.pojo.query.MaterialQuery;
import com.cyl.wms.service.MaterialService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description ="物料接口列表")
@RestController
@RequestMapping("/wms/material")
public class MaterialController extends BaseController {
    @Autowired
    private MaterialService service;

    @ApiOperation("查询物料列表")
    @PostMapping("/list")
    public ResponseEntity<Page<Material>> list(@RequestBody MaterialQuery query, Pageable page) {
        List<Material> list = service.selectList(query, page);
        return ResponseEntity.ok(new PageImpl<>(list, page, ((com.github.pagehelper.Page)list).getTotal()));
    }
    @ApiOperation("查询全部物料列表")
    @PostMapping("/listAll")
    public ResponseEntity<List<Material>> listAll(@RequestBody MaterialQuery query) {
        List<Material> list = service.selectListAll(query);
        return ResponseEntity.ok(list);
    }

    @ApiOperation("新增物料")
    @PostMapping
    public ResponseEntity<Integer> add(@RequestBody Material material) {
        return ResponseEntity.ok(service.insert(material));
    }


    @ApiOperation("删除物料")
    @Log(title = "物料", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public ResponseEntity<Integer> remove(@PathVariable Long[] ids) {
        return ResponseEntity.ok(service.deleteByIds(ids));
    }


}
